import type { Recordable } from '#/types/global';
import { type ComputedRef, unref } from 'vue';

export function useVxeMethods(getVxeTableRef: ComputedRef) {
  function vxeGetTableColumn() {
    let data = [];
    if (unref(getVxeTableRef)) {
      data = unref(getVxeTableRef).getTableColumn();
    } else {
      console.error('getVxeTableRef不存在');
    }
    return data;
  }
  //加载列配置并恢复到初始状态（对于表格列需要重载、局部递增场景下可能会用到）
  function vxeReloadColumn(columns: Recordable[]) {
    if (unref(getVxeTableRef)) {
      unref(getVxeTableRef).reloadColumn(columns);
    } else {
      console.error('getVxeTableRef不存在');
    }
  }
  return { vxeGetTableColumn, vxeReloadColumn };
}
